// import store from '@/store'
import axios from 'axios'
import { getToken } from './auth'
import { Message } from 'element-ui'
// 创建一个axios实例
const request = axios.create({
  baseURL: '/manager',
  timeout: 5000
})
request.interceptors.request.use(function(config) {
  if (getToken()) {
    config.headers.Authorization = getToken()
  }
  return config
}, function(error) {
  return Promise.reject(error)
})

// 添加响应拦截器
request.interceptors.response.use(function(response) {
  if (response.data instanceof Blob) return response.data
  if (response.data.code !== 200) {
    Message.error(response.data.msg)
    return Promise.reject(response.data.msg)
  }
  return response.data
}
, function(error) {
  // if (error.response.status === 401) {

  // }
  Message.error(error.data.msg)
  return Promise.reject(error)
})
export default request
